#ifndef __TCP_SOCKET_H__
#define __TCP_SOCKET_H__

#include <string>
#include <iostream>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <cstring>

using std::string;

class TcpSocket{
public:
    TcpSocket();
    TcpSocket(int socket);
    ~TcpSocket();
    int connectToHost(string ip, unsigned short port);
    int sendMsg(string msg);
    string recvMsg();
private:
    int readn(char* buf, int size);
    int writen(const char* msg, int size);
private:
    int m_fd; //通信的套接字
};

#endif